<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>我的</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp bg">
		<div class="app_head">
			<span class="left back"></span>
			<span class="name">我的收藏</span>
			<span class="right">
				<a href="javascript:;" class="edit" tapmode onclick="edit()">编辑收藏夹</a>
			</span>
		</div>
		<div class="app_col_nav clearfix">
			<div id="temp_nav" class="app_col_inner_nav menuflex loaded animated fadeIn">

				<a href="javascript:;" tapmode onclick="showContents(0)" class="active">课程</a>
				<a href="javascript:;" tapmode onclick="showContents(1)">文章</a>

			</div>
		</div>

		<div class="nocontent_0 nocontent animated fadeInUp" style="display: none">
			<img src="../../lib/img/nocomment.png" alt="">
			<div class="text">
				抱歉，未能得到相关数据
			</div>
		</div>
		<div class="nocontent_1 nocontent animated fadeInUp">
			<img src="../../lib/img/loading.gif" class="minimize" alt="">
			<div class="text minimize">
				准备数据中...
			</div>
		</div>
		<div class="app_main soucang">
			<div class="space"></div>
			<div class="app_box">
				<div id="soucang_list" class="box_cont padding_box"></div>
			</div>
		</div>
		<div class="list_delete_line animated fadeInUp hide">
			<span class="checker" tapmode onclick="checnAll(this)"></span>
			<a href="javascript:;" class="delete_sel" tapmode onclick="deleteMsg()">删除选中条目</a>
		</div>
	</div>
</div>
<script id="soucang_list_template" type="text/html">
	<ul class="lesson_list list_item line_list biger clearfix animated fadeInUp">

		<% if(lesson===null){ %>

		<li class="nocontent por">
			<img src="../../lib/img/noproducts.png" alt="">
			<div class="text">
				暂无
			</div>
		</li>

		<% }else{ for(var i in lesson){ var _lesson_=lesson[i] %>

		<li tapmode onclick="viewLesson(this,<%:=_lesson_.id%>)">
			<span class="checker" data_id="<%:=_lesson_.id%>"></span>
			<img class="pic imgcache" src="<%:=_lesson_.cover%>" data_src="<%:=_lesson_.cover%>" alt="">
			<span class="title">
				<%:=_lesson_.title%>
			</span>
			<span class="intro">
				<%:=_lesson_.author%> <%:=_lesson_.viewnum%>观看
			</span>
			<span class="tag tag_skin"><%:=_lesson_.integral===0?'免积分':(_lesson_.integral+'积分观看')%></span>
		</li>

		<% }} %>

	</ul>
	<ul class="article_list list_item line_list hide clearfix animated fadeInUp">

		<% if(article===null){ %>

		<li class="nocontent por">
			<img src="../../lib/img/noproducts.png" alt="">
			<div class="text">
				尚未收藏文章
			</div>
		</li>

		<% }else{ for(var i in article){ var _article_=article[i] %>

		<li tapmode onclick="viewArticle(this,'<%:=_article_.href%>')">
			<span class="checker" data_id="<%:=_article_.id%>"></span>
			<img class="pic imgcache" src="<%:=img%>" data_src="<%:=_article_.cover%>" alt="">
			<span class="comname">
				<%:=_article_.title%>
			</span>
			<span class="intention">
				<%:=_article_.author%> / <%:=_article_.time%>
			</span>
		</li>

		<% }} %>

	</ul>

</script>
<script>
	var itemNum = 0,
		editing = false,
		edit = function () {},
		tgc = function (obj) {
			$(obj).find('.checker').toggleClass('checked');
		},
		viewLesson = function (obj, id) {
			if (editing) {
				tgc(obj)
			} else {
				$(obj).addClass('readed');
				_$.getView('class',id,obj)
			}
		},
		viewArticle = function (obj, href) {
			if (editing) {
				tgc(obj)
			} else {
				href && _$.getPage(href);
			}
		}
		checnAll = function (obj) {
			var allItem = $(['.lesson_list','.article_list'][itemNum]);
			if ($(obj).hasClass('checked')) {
				allItem.find('.checker').removeClass('checked');
				$(obj).removeClass('checked');
			} else {
				allItem.find('.checker').addClass('checked');
				$(obj).addClass('checked');
			}
		},
		deleteMsg = function () {
			var ids = [], allItem = $(['.lesson_list', '.article_list'][itemNum]).find('.checker.checked');
			if (allItem.length > 0) {
				allItem.map(function (i) {
					ids.push(parseInt(allItem.eq(i).attr('data_id')));
				})
				_$.ajax({
					interface: 'delCollect',
					data: {
						ids: ids,
						type: itemNum + 1
					},
					call: function (data) {
						console.log(JSON.stringify(data));
						if (data.status === 200) {
							allItem.parent().remove();
							editing = true;
							edit();
							checkListLength();
						} else {
							api.toast({
								msg: data.msg
							})
						}
					}
				})
			}
		},
		checkListLength = function () {
			$('.list_item').addClass('hide');
			var obj = $(['.lesson_list','.article_list'][itemNum]);
			if (obj.find('li').length > 0 ? true : false) {
				obj.removeClass('hide');
			}else{
				obj.html(
					'<li class="nocontent por">' +
					'<img src="../../lib/img/noproducts.png" alt="">' +
					'<div class="text">' +
					'暂无' +
					'</div>' +
					'</li>'
				);
				obj.removeClass('hide');
			}
		},
		showContents = function (curentItem) {
			itemNum = curentItem;
			$('.app_main').removeClass('editing');
			$('.app_col_inner_nav a').removeClass('active').eq(curentItem).addClass('active');
			checkListLength();
			edit(true);
		},
		appready = function (){
			_$.ajax({
				interface:'getCollect',
				call:function(data){
					if(data.status===200){
						_$.template('soucang_list_template',data.data,function(html){
							$('.nocontent_1').fadeOut();
							_$.sleep(function(){
								$('#soucang_list').html(html);
								_$.imgCache.load();
								$('.app_main').removeClass('hide');
							},250)
							edit = function (status) {
								if(status===true){
									editing = true;
								}
								if (editing) {
									console.log('editing');
									$('.checker').removeClass('checked');
									$('.app_main').removeClass('editing');
									$('.list_delete_line').addClass('hide').find('.checker').removeClass('active');
								} else {
									console.log('notediting');
									$('.app_main').addClass('editing');
									$('.list_delete_line').removeClass('hide');
								}
								editing = !editing;
							}
						})
					}else{
						$('.app_col_nav,.nocontent_1').fadeOut();
						_$.sleep(function(){
							$('.nocontent_0').fadeIn();
						},500)
					}
				}
			})
		};
</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>